import spacy
import networkx as nx


nlp = spacy.load("en_core_web_sm")


doc = nlp(u'Ten buckets of water were poured into a vacant land outside the house.')


for token in doc:
    print((token.head.text, token.text, token.dep_))


doc = nlp(u"Ten buckets of water were poured into a vacant land outside the house.")



spacy.displacy.serve(doc, style='dep')



text = u'A trillion gallons of water have been poured into an empty region of outer space.'
entity1 = 'water'.lower()
entity2 = 'region'
doc = nlp(text)

print('sentence:',format(doc))
# Load spacy's dependency tree into a networkx graph
edges = []
for token in doc:
    for child in token.children:
        edges.append(('{0}'.format(token.lower_),
                      '{0}'.format(child.lower_)))
graph = nx.Graph(edges)
# Get the length and path
print('shortest path lenth: ',nx.shortest_path_length(graph, source=entity1, target=entity2))
print('shortest path: ',nx.shortest_path(graph, source=entity1, target=entity2))





import spacy
import networkx as nx


nlp = spacy.load("en_core_web_sm")


# doc = nlp("JIngbo who dresses a green T-shirt was instructed by Chen.")
doc = nlp("Ten buckets of water were poured into a vacant land outside the house.")


for token in doc:
    print((token.head.text, token.text, token.dep_))


edges = []
for token in doc:
    for child in token.children:
        edges.append(('{0}'.format(token.lower_),
                      '{0}'.format(child.lower_)))
graph = nx.Graph(edges)
entity1 = "water".lower()
entity2 = 'land'.lower()
print('shortest path lenth: ',nx.shortest_path_length(graph, source=entity1, target=entity2))
print('shortest path: ',nx.shortest_path(graph, source=entity1, target=entity2))



